package com.aries.remoteplus.view;


import com.aries.remoteplus.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class AddServerActivity extends Activity {

	private String serverName;
	private String ipAddress;
	private String tcpPort;
	private String udpPort;
	private String mac;
	private String passWord;
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.server);
		
		Spinner typeSpinner = (Spinner) this.findViewById(R.id.server_type);
		ArrayAdapter spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.pref_client_entries, 
																	android.R.layout.simple_spinner_item);
		
		spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		typeSpinner.setAdapter(spinnerAdapter);
		typeSpinner.setEnabled(false);
		
		Button saveButton = (Button) this.findViewById(R.id.save);
		saveButton.setOnClickListener(new saveButtonListener());
	}
	
	private class saveButtonListener implements OnClickListener {

		@Override
		public void onClick(View v)
		{
			// TODO Auto-generated method stub
			Intent dataIntent = new Intent();
			
			EditText serverNameEditText = (EditText) AddServerActivity.this.findViewById(R.id.server_name);
			EditText ipAddressEditText 	= (EditText) AddServerActivity.this.findViewById(R.id.host_ip);
			EditText tcpPortEditText	= (EditText) AddServerActivity.this.findViewById(R.id.tcp_port);
			EditText udpPortEditText	= (EditText) AddServerActivity.this.findViewById(R.id.udp_port);
			EditText macEditText		= (EditText) AddServerActivity.this.findViewById(R.id.server_mac);
			EditText passwordEditText 	= (EditText) AddServerActivity.this.findViewById(R.id.password);
			
			serverName 	= serverNameEditText.getText().toString();
			ipAddress	= ipAddressEditText.getText().toString();
			tcpPort		= tcpPortEditText.getText().toString();
			udpPort		= udpPortEditText.getText().toString();
			mac			= macEditText.getText().toString();
			passWord	= passwordEditText.getText().toString();
			
			dataIntent.putExtra("serverName", serverName);
			dataIntent.putExtra("ipAddress", ipAddress);
			dataIntent.putExtra("tcpPort", tcpPort);
			dataIntent.putExtra("udpPort", udpPort);
			dataIntent.putExtra("mac", mac);
			dataIntent.putExtra("passWord", passWord);
			
			setResult(RESULT_OK, dataIntent);
			finish();
		}
		
	}
	
}
